#pragma once
#include "config.h"
#include <smart_serve_log.h>
#include "nlohmann/json.hpp"
#include <fstream>

using json = nlohmann::json;

namespace OHOS {
namespace SmartServe {

class ConfigLoader {
public:
    static bool LoadFromFile(const std::string& filePath, Config& config)
    {
        std::ifstream in(filePath);
        if (!in.is_open()) {
            SMART_SERVE_LOGE("[LoadFromFile] fail to open file %s", filePath.c_str());
            return false;
        }
        json configJson;
        try {
            configJson = json::parse(in);
            config = configJson.get<Config>();
        } catch (const json::exception& e) {
            SMART_SERVE_LOGE("[InitDevManager] Json parse error: %s", e.what());
            return false;
        }
        return true;
    }
};

} // namespace SmartServe
} // namespace OHOS